<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::any('login', 'AuthController@login')->name('login');

//Route::middleware(['refresh.token'])->group(function () {
Route::group(['middleware' => ['refresh.token']], function () {
    Route::post('logout', 'AuthController@logout');
    Route::get('profile', 'AuthController@profile');
    //系统管理
//    Route::namespace('System')->prefix('system')->middleware('permission:system/manage')->group(function () {
    Route::group(['prefix' => 'system', 'middleware' => ['permission:system/manage']], function() {
        //获取`用户/角色/权限`数据
        Route::get('data', 'AuthController@data')->middleware('permission:system/users|system/roles|system/permissions');
        Route::group(['namespace' => 'System'], function () {
            //用户管理
            Route::group(['prefix' => 'users', 'middleware' => ['permission:system/users']], function () {
                Route::get('/', 'UserController@index');
                //添加
                Route::post('/', 'UserController@store')->middleware('permission:system/users/create');
                //编辑
                Route::put('{id}', 'UserController@update')->middleware('permission:system/users/update');
                //删除
                Route::delete('{id}', 'UserController@destroy')->middleware('permission:system/users/destroy');
            });
            //角色管理
            Route::group(['prefix' => 'roles', 'middleware' => ['permission:system/roles']], function () {
                Route::get('/','RoleController@index');
                //添加
                Route::post('/','RoleController@store')->middleware('permission:system/roles/create');
                //编辑
                Route::put('{id}','RoleController@update')->middleware('permission:system/roles/update');
                //删除
                Route::delete('{id}','RoleController@destroy')->middleware('permission:system/roles/destroy');
            });
            //权限管理
            Route::group(['prefix' => 'permissions', 'middleware' => ['permission:system/permissions']], function () {
                Route::get('/','PermissionController@index');
                //添加
                Route::post('/','PermissionController@store')->middleware('permission:system/permissions/create');
                //编辑
                Route::put('{id}','PermissionController@update')->middleware('permission:system/permissions/update');
                //删除
                Route::delete('{id}','PermissionController@destroy')->middleware('permission:system/permissions/destroy');
            });
        });

    });
});
